package com.guyaogg.gulimall.cart.config;

import com.guyaogg.gulimall.cart.interceptor.CartInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 顾遥
 */
@Configuration
public class GulimallWebConfig implements WebMvcConfigurer {

    private final CartInterceptor cartInterceptor;

    public GulimallWebConfig(CartInterceptor cartInterceptor) {
        this.cartInterceptor = cartInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // 添加拦截器，且拦截所有请求
        registry.addInterceptor(cartInterceptor).addPathPatterns("/**");
    }
}
